﻿#include <QCoreApplication>
#include "CLogOper.h"

void CLogOper::addMsg(SExecLog sExecLog)
{
	m_lpAddMsg(m_sModuleName, sExecLog.m_sDevName, sExecLog.m_sFuncName, sExecLog.m_nAlarmLevel,sExecLog.m_sDescriptionl);
}

QWidget* CLogOper::createLogWidget(QString sDevName)
{
	QWidget* widget = m_lpCreateLogWidget(m_sModuleName, sDevName);
	return widget;
}

void CLogOper::destroyLogWidget(QWidget* widget)
{
	if (m_lpDestroyLogWidget)
	{
		m_lpDestroyLogWidget(widget);
	}
}

void CLogOper::setModuleName(QString sName)
{
	m_sModuleName = sName;
}

CLogOper::CLogOper()
{
	m_sModuleName = QString::fromLocal8Bit("跑偏检测");
	//获取当前驱动路径
	QString sDllPath = QCoreApplication::applicationDirPath() + "/LogWidget.dll";
	m_pLibrary = new QLibrary(sDllPath);
	if (!m_pLibrary->load())
	{
		delete m_pLibrary;
		m_pLibrary = nullptr;
	}
	else
	{
		m_lpAddMsg = (AddMsg)m_pLibrary->resolve("addMsg");
		m_lpCreateLogWidget = (CreateLogWidget)m_pLibrary->resolve("createLogWidgte");
		m_lpDestroyLogWidget = (DestroyLogWidget)m_pLibrary->resolve("destroyLogWidget");
		if (!m_lpAddMsg || !m_lpCreateLogWidget)
		{
			m_pLibrary->unload();
			delete m_pLibrary;
			m_pLibrary = nullptr;
		}
	}
}

CLogOper::~CLogOper()
{
	
}
